#include "serial.h"
int open_usb(char *dev)
{
        int fd;

        fd=open(dev,O_RDWR);
        if (-1 == fd)
        {
            perror("open com error!\n");
            return -1;
        }
        struct  termios Opt;
        tcgetattr(fd, &Opt);
        tcflush(fd,TCIFLUSH);
        cfsetispeed(&Opt,B115200);
        cfsetospeed(&Opt,B115200);

        Opt.c_cflag |= CS8;
        Opt.c_cflag &= ~PARENB;
        Opt.c_oflag &= ~(OPOST);
        Opt.c_cflag &= ~CSTOPB;
        Opt.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN);
        Opt.c_iflag &= ~(INPCK|BRKINT|ICRNL|ISTRIP|IXON);
        Opt.c_cc[VMIN] = 0;
        Opt.c_cc[VTIME] = 0;

        if (tcsetattr(fd,TCSANOW,&Opt) != 0)
        {
                perror("SetupSerial!\n");
                close(fd);
                return -2;
        }
        return fd;
}
